<template>
    <div class="vipCont" :style="'min-height: '+docheight+'px'">
      <div  v-if="!showTimeOut">
        <!-- <topcpm :topobj="topobj"></topcpm> -->
        <div class="bannerCont">
          <img src="static/img/payBanner.png">
          <div class="maskCont">
            <div class="maskTop">
                <div class="maskTitle">SVIP</div>
                <div class="maskName">开通超级会员</div>
                <div class="maskDes">优享全场折扣特权</div>
            </div>
            <div class="userInfo">
                <div class="userImg">
                    <img :src="userInfo.head_img+ossSrc" />
                </div>
                <div class="userInfoDes">
                    <div class="userInfoDesItem">会员身份：{{ userInfo.is_member==1?'普通会员':'超级会员' }}</div>
                    <div class="userInfoDesItem">专享折扣：{{ userInfo.is_member==1?'- -':'全场'+userInfo.member_discount/10+'折' }}</div>
                    <div class="userInfoDesItem">到期时间：{{ userInfo.is_member==1?'- -':userInfo.member_expiration_time }}</div>
                </div>
            </div>
          </div>
        </div>
        <div class="buyVipCont" v-if="userInfo.is_member==1">
          <div class="buyVipTop">
            <div class="buyVipTopVal">年费SVIP会员</div>
          </div>
          <div class="vipStep">
            <div class="vipMoney">¥<span>{{ userInfo.shop_info.shop_membership_fee }}</span></div>
            <!-- <div class="vipTime">低至0.06元/天</div> -->
            <div class="vipTime">*会员权益：全场{{ Number(userInfo.shop_info.member_discount)/10 }}折！</div>
          </div>
        </div>
        <div class="payType" v-if="userInfo.is_member==1">
          <div class="payTop">支付方式</div>
          <div class="payItem" @click="checkPayFn(index)" :key="index" v-for="(item,index) in checkPay">
            <div :class="'payTypeIcon iconfont '+item.icon"></div>
            <div class="payName">{{item.val}}</div>
            <div :class="index==checkPayId?'payCheck iconfont icon-gouxuan1':'unpayCheck iconfont icon-gouxuan1'"></div>
          </div>
        </div>
        <div class="openCont" v-if="userInfo.is_member==2">
          <div class="openTop">开通记录</div>
          <div :class="index==0?'openList noBorder':'openList'" :key="index" v-for="(item,index) in menberList">
            <div class="openLeft">
                <div class="openNum">年费会员</div>
                <div class="openTime">{{ item.create_time }}</div>
            </div>
            <div class="openMoney">-{{ item.money }}</div>
          </div>
        </div>
        <div class="sureBtn" v-if="userInfo.is_member==1" @click="payfn">开通SVIP</div>
        <toast v-model="showToast" position="middle" width="50%" type="text" :time="1000">{{showText}}</toast>
      </div>
      <getLoad v-if="!showCont"></getLoad>
      <getTimeOut v-if="showTimeOut"></getTimeOut>
    </div>
  </template>
  
  <script>
    import topcpm from '@/components/topcpm.vue'
    import {memberPay,my,user_member} from "@/http/api";
    import {Toast } from 'vux'
    import getLoad from '@/components/public/getLoad'
    import getTimeOut from '@/components/public/getTimeOut'
    import WeixinJSBridge from 'weixin-js-sdk'
  
  export default {
    components: {getLoad,getTimeOut,topcpm,Toast},
    data() {
      return {
        showTimeOut: false,
        showCont:true,
        showText:'',
        showToast:false,
        topobj:{
          is_bg:true,
          rightVal:'',
          centerVal:'会员充值',
        },
  
        checkPay:[
          {val:'微信',icon:'icon-weixin1'},
        ],
        checkPayId:0,
        userInfo:{},
        menberList:[],
      }
    },
    props: {},
    methods: {
      checkRadioFn(val){
          this.checkLink = val
      },
      payfn(){
        var data = {}
        memberPay(data).then((res)=>{
          if(res.data.code==1){
            this.wxPayFn(res)
          }else{
            this.showToast = true
            this.showText = res.data.msg
          }
        })
      },
      wxPayFn(res){
        WeixinJSBridge.invoke('getBrandWCPayRequest', {
          appId: res.data.data.appId,   //公众号ID，由商户传入    
          timeStamp: res.data.data.timeStamp,   //时间戳，自1970年以来的秒数    
          nonceStr: res.data.data.nonceStr,      //随机串    
          package: res.data.data.package,
          signType: res.data.data.signType,     //微信签名方式：    
          paySign: res.data.data.paySign, //微信签名
        },
        (resData)=>{
            if (resData.err_msg == "get_brand_wcpay_request:ok") {
                // 使用以上方式判断前端返回,微信团队郑重提示：
                //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                this.showToast = true
                this.showText = '充值成功'
                this.getData()
              }else{
                this.showToast = true
                this.showText = '充值失败'
              }
        })
      },
      checkPayFn(index){
        this.checkPayId = index
      },
      getData(){
        my().then((res)=>{
          if(res.data.code==1){
            this.userInfo = res.data.data
            this.getMenberList()
            }else{
            this.showToast = true
            this.showText = '用户信息获取失败'
            }
            this.showCont= true
        }).catch(()=>{
          this.showTimeOut = true
          this.showCont= true
          })
      },
      getMenberList(){
        
        user_member().then((res)=>{
          if(res.data.code==1){
            this.menberList = res.data.data
          }else{
            this.showToast = true
            this.showText = res.data.msg
            }
        }).catch(()=>{
            this.showTimeOut = true
            this.showCont= true
          })
      },
    },
    mounted() {
    },
    created() {
        this.getData()
    },
  }
  </script>
  
  <style scoped lang="less">
  .vipCont{
    width: 100%;
    background-color: #f9f1f1;
    padding-bottom: 1.5rem;
    box-sizing: border-box;
    .bannerCont{
      width: 100%;
      box-sizing: border-box;
      font-size: 0;
      position: relative;
      img{
        width: 100%;
        border-radius: 0.25rem;
      }
      .maskCont{
        position: absolute;
        left: 0;
        top: 0;
        padding: 0.75rem 4%;
        box-sizing: border-box;
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        font-size: 0.6rem;
        color: #643F10;
        .maskTop{
            .maskTitle{
                font-size: 1.8rem;
            }
            .maskName{
                font-size: 0.9rem;
            }
            .maskDes{
                font-size: 0.6rem;
            }
        }
        .userInfo{
            display: flex;
            align-items: center;
            padding: 0.5rem;
            border-radius: 0.5rem;
            box-sizing: border-box;
            background-color: rgba(255, 255, 255, 0.5);
            .userImg{
                height: 2.5rem;
                border: 3px solid #fff;
                border-radius: 50%;
                margin-right: 0.75rem;
                width: 2.5rem;
                font-size: 0;
                img{
                    height: 100%;
                    border-radius: 50%;
                }
            }
            .userInfoDes{
                height: 2.5rem;
                padding: 0.15rem 0;
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                box-sizing: border-box;
            }
        }
      }
    }
    .buyVipCont{
      width: 92%;
      margin: 1.5rem auto;
      padding: 0.75rem 4%;
      box-sizing: border-box;
      border-radius: 0.5rem;
      background-color: #fff;
      .buyVipTop{
        width: 100%;
        display: flex;
        align-items: center;
        .buyVipTopVal{
          font-size: 0.8rem;
          font-weight: bold;
        }
      }
      .vipStep{
        width: 100%;
        padding-top: 0.75rem;
        padding-bottom: 0.5rem;
        color: #643F10;
        text-align: center;
        .vipMoney{
            font-size: 2rem;
        }
      }
    }
    .payType{
      width: 92%;
      padding: 0.75rem 4%;
      box-sizing: border-box;
      border-radius: 0.5rem;
      margin: 1.5rem auto;
      background-color: #fff;
      .payTop{
        font-size: 0.8rem;
        font-weight: bold;
      }
      .payItem{
        width: 100%;
        display: flex;
        box-sizing: border-box;
        margin-top: 0.75rem;
        align-items: center;
        display: flex;
        .payName{
          flex: 1;
          width: 0.5rem;
          font-size: 0.7rem;
          margin: 0 0.75rem;
          color: #e95551;
        }
        .payTypeIcon{
          font-size: 1.75rem;
          color: #28C445;
        }
        .payCheck,.unpayCheck{
          width: 1rem;
          height: 1rem;
          border-radius: 50%;
          background-color:#e95551;
          color: white;
          font-size: 0.7rem;
          text-align: center;
          line-height: 1rem;
        }
        .unpayCheck{
          background-color: rgb(230,230,230);
        }
      }
    }
    .openCont{
        width: 92%;
        padding: 0.75rem 4%;
        box-sizing: border-box;
        border-radius: 0.5rem;
        margin: 1.5rem auto;
        background-color: #fff;
        .openTop{
            font-size: 0.8rem;
            font-weight: bold;
        }
        .openList{
            display: flex;
            padding: 0.75rem 0;
            box-sizing: border-box;
            align-items: center;
            border-top: 1px dashed #e95551;
            justify-content: space-between;
            .openNum{
                font-weight: bold;
                margin-bottom: 0.25rem;
            }
            .openTime{
                color: #e95551;
                font-size: 0.6rem;
            }
            .openMoney{
                color: #e95551;
                font-size: 0.8rem;
            }
        }
        .noBorder{
            border-top: none;
        }
    }
    .sureBtn{
      width: 92%;
      line-height: 2.2rem;
      background-color: #e95551;
      position: fixed;
      bottom: 0.75rem;
      left: 4%;
      text-align: center;
      color: white;
      box-shadow: 0 0 0.75rem #FCF8F2;
      border-radius: 0.25rem;
    }
  }
  </style>
  